package utils

import (
	"context"
	"encoding/json"
	log "github.com/sirupsen/logrus"
	"time"
)

func Logf(ctx context.Context, funcName string, req interface{}) func(rsp interface{}) {
	t := time.Now()
	return func(rsp interface{}) {
		log.Debugf("[%s]->request:%v, response:%v, cost:%s", funcName, Json(req), Json(rsp), time.Since(t))
	}
}

func Json(st interface{}) string {
	r, _ := json.Marshal(st)
	return string(r)
}
